﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CE.iPhone.PList;
using cczEdit.DramaDialog;
namespace cczEdit.CommonInstructComposite
{
    public partial class UCCIUnitNeighbor : UserControl,ICommonInstruct
    {

        public UCCIUnitNeighbor()
        {
            InitializeComponent();
            foreach (Hero hero in UCDrama.heros)
            {

                comboBoxName1.Items.Add(hero.name);
                comboBoxName2.Items.Add(hero.name);
            }
        }

        private PListDict CreateSwerveDict(long unitID1, long unitID2)
        {
            PListDict dict = AddDramaDialog.CreateInstructDict(kInstructType.kInstructTypeBattleSwerve);
            dict["UnitID1"] = new PListInteger(unitID1);
            dict["UnitID2"] = new PListInteger(unitID2);
            return dict;
        }

        public PListDict CreatResultDict()
        {
            Hero hero1 = UCDrama.heros.Find(h => h.name == comboBoxName1.Text);
            if (hero1 == null)
            {
                MessageBox.Show("没有这个武将,请重试或尝试从下拉框选择");
                return null;
            }
            Hero hero2 = UCDrama.heros.Find(h => h.name == comboBoxName2.Text);
            if (hero2 == null)
            {
                MessageBox.Show("没有这个武将,请重试或尝试从下拉框选择");
                return null;
            }
            PListDict section = new PListDict();
            section.Add("Information", new PListString(hero1.name +" "+hero2.name+" 相邻测试"));
            PListArray conditions = new PListArray();
            PListDict neighborTestDict = AddDramaDialog.CreateConditionDict(kLogicalTestType.kLogicalTestTypeNeightbour);
            neighborTestDict["UnitID1"] = new PListInteger(hero1.num);
            neighborTestDict["UnitID2"] = new PListInteger(hero2.num);
            conditions.Add(neighborTestDict);

            PListDict varTestDict = AddDramaDialog.CreateConditionDict(kLogicalTestType.kLogicalTestTypeVariable);
            varTestDict["TrueVariables"] = new PListArray();
            PListArray falseVars = new PListArray();
            falseVars.Add(new PListInteger((long)numericUpDownVar.Value));
            varTestDict["FalseVariables"] = falseVars;
            conditions.Add(varTestDict);

            section.Add("Condition", conditions);
            PListArray dramas = new PListArray();
            dramas.Add(UCDrama.GetInstructDict(kInstructType.kInstructTypeDramaBegin));
            
            dramas.Add(CreateSwerveDict(hero1.num,hero2.num));
            dramas.Add(CreateSwerveDict(hero2.num, hero1.num));

            PListDict dialogDict1 = AddDramaDialog.CreateInstructDict(kInstructType.kInstructTypeDialog);
            dialogDict1["UnitID"] = new PListInteger(hero1.num);
            dialogDict1["Message"] = new PListString(textBoxWord1.Text);
            dramas.Add(dialogDict1);

            PListDict dialogDict2 = AddDramaDialog.CreateInstructDict(kInstructType.kInstructTypeDialog);
            dialogDict2["UnitID"] = new PListInteger(hero2.num);
            dialogDict2["Message"] = new PListString(textBoxWord2.Text);
            dramas.Add(dialogDict2);

            PListDict varSetDict = AddDramaDialog.CreateInstructDict(kInstructType.kInstructTypeVariableSet);
            varSetDict["VariableIndex"] = new PListInteger((long)numericUpDownVar.Value);
            varSetDict["Value"] = new PListBool(true);
            dramas.Add(varSetDict);
            
            dramas.Add(UCDrama.GetInstructDict(kInstructType.kInstructTypeDramaOver));
            section.Add("Dramas", dramas);
            return section;
        }
    }
}
